using Comdiv.Extensions;
using Comdiv.Model;
using Comdiv.Model.Interfaces;
using Comdiv.Logging;
using Comdiv.Application;
using Comdiv.Persistence;
using Comdiv.Inversion;
using Comdiv.Security.Acl;
using Comdiv.Conversations;
using Comdiv.IO;
using Comdiv.Security;
using System.Linq;

namespace Comdiv.Dbfs{
    public class MimeHelper : IMimeHelper{
        public string GetMimeByExtension(string extension){
            var ext = extension.Replace(".", "");
            var byxml = myapp.files.ReadXml("mime.config?$" + ext);
            if(byxml.hasContent()){
                return byxml;
            }
            switch (ext){
                case "txt":
                    return "text/plain";
                case "xls":
                    return "application/vnd.ms-excel";
                case "doc":
                    return "application/vnd.ms-word";
                case "docx":
                    return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                case "xlsx":
                    return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                case "css":
                    return "text/css";
                case "js":
                    return "text/javascript";
                case "png":
                    return "image/png";
                case "jpg":
                    return "image/jpeg";
                case "jpeg":
                    return "image/jpeg";
                case "gif":
                    return "image/gif";
                case "pdf":
                    return "application/pdf";
                case "html":
                    return "text/html";
                case "htm":
                    return "text/html";
                case "zip":
                    return "multipart/x-zip";
                case "rar":
                    return "application/x-rar-compressed";
                case "xml":
                    return "text/xml";
            }

            return "bin/unknown";
        }
    }
}